<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>

<body>
    <h2>历史搜索</h2>
    <input type="text" id="input">

    <div id="app"></div>
    <script>
        var historys = [];
        $("#input").keydown(function (event) {
            if (event.keyCode == 13) {
                if (this.value != '' && historys.indexOf(this.value) == -1)
                    {
                        var p = document.createElement('p');
                        p.innerHTML = this.value;
                        console.log(p)
                        $("#app").prepend(p);
                        historys.unshift(this.value)
                        console.log(historys);
                        $(this).val('')
                    }
                else{
                    alert("输入的字段不能为空不能为相同字段")
                    $(this).val('')
                }
            }
        })
    </script>
</body>

</html>